package com.ht.medicaltreatment.viewmodel

import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.ToastUtils
import com.ht.medicaltreatment.api.RetrofitUtils
import com.ht.medicaltreatment.bean.CentrifugeNormalRecordBean
import com.ht.medicaltreatment.bean.CentrifugeOverTimeBean
import com.ht.medicaltreatment.bean.ProjectBean
import com.xgst.driverlesscars.api.ApiService
import com.xgst.lib.http.ApiResult
import kotlinx.coroutines.launch

class CentrifugeRecordViewModel:BaseViewModel() {
    //模糊查询离心订单
    fun queryCentrifugeOrder(beginTime : String,
                             centrifugeId : String,
                             endTime : String,
                             name : String,
                             projectId : String, onSuccess:(MutableList<CentrifugeNormalRecordBean>?)->Unit,
                             onError:(String)->Unit){
        viewModelScope.launch {
            val bean = mApi.queryCentrifugeOrder(beginTime,centrifugeId,endTime,name,projectId)
            when(bean){
                is ApiResult.Success -> onSuccess(bean.data.data)
                is ApiResult.Error -> onError(bean.errorMessage)
            }
        }
    }

    //项目
    fun projects(onResult:(MutableList<ProjectBean>)->Unit){
        viewModelScope.launch {
            val bean = mApi.projects()
            when(bean){
                is ApiResult.Success -> onResult(bean.data.data!!)
                is ApiResult.Error ->  ToastUtils.showShort(bean.errorMessage)
            }
        }
    }

    fun overTimeList(id:String,onResult:(MutableList<CentrifugeOverTimeBean>?)->Unit,onError:(String)->Unit){
        viewModelScope.launch {
            val bean = mApi.overTimeList(id)
            when(bean){
                is ApiResult.Success -> onResult(bean.data.data)
                is ApiResult.Error ->  onError(bean.errorMessage)
            }
        }
    }

    fun addRemark(centrifugeId: String,remark:String,onResult:()->Unit,onError:(String)->Unit){
        viewModelScope.launch {
            val bean = mApi.addRemark(centrifugeId,remark)
            when(bean){
                is ApiResult.Success -> onResult()
                is ApiResult.Error ->  onError(bean.errorMessage)
            }
        }
    }
}